line = input("Введите скобочную последовательность:\n")
symbols_raw = list(r"{}()<>[]")
symbols: list[tuple[str, str]] = [('{', '}'), ('(', ')'), ('<', '>'), ('[', ']')]
start_sp = {}
end_sp = {}
for index, x in enumerate(symbols):
    start, end = x
    start_sp[start] = index
    end_sp[end] = index
formatted_input = ''.join(filter(lambda c: c in symbols_raw, line.strip()))
stk = []
good = True
for c in formatted_input:
    if c in start_sp:
        stk.append(start_sp[c])
    elif c in end_sp:
        if len(stk)==0 or end_sp[c] != stk[-1]:
            good = False
            break
        else:
            stk.pop()
if not good or len(stk)!=0:
    print("False")
else:
    print("True")
